const express = require('express');
const router = express.Router();
const con = require("../model/db");
const mime = require('mime');
const multer = require('multer');
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, './uploads')
    },
    filename: function (req, file, cb) {
        const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
        let extname=mime.getExtension(file.mimetype);
        cb(null, file.fieldname + '-' + uniqueSuffix+"."+extname);
    }
})

const upload = multer({ storage: storage })
router.post('/',upload.single('avatar'), function (req, res) {
    res.json({
        url:"/"+req.file.filename,
    })
})
module.exports = router;